Ubuntu touch Command: Quickly Create Empty Files

In the Ubuntu system, the `touch` command is a practical utility for creating empty files. Its core function is to quickly generate empty files. If the target file already exists, it only updates its access and modification timestamps without altering the content. Basic usage includes: creating a single file (e.g., `touch test.txt`), creating multiple files in bulk (separated by spaces, e.g., `touch file1.txt file2.txt`), and specifying a path to create a file (e.g., `touch ~/Documents/note.txt`). When using it, note that if the directory in the target path does not exist, you need to first create the multi-level directory using `mkdir -p`. If permission is insufficient, you can use `sudo` to elevate privileges (e.g., `sudo touch /root/test.txt`). If the file already exists, only the modification time will be updated, and the content remains unchanged. Summary: The `touch` command is simple and efficient, supporting multiple files and path specification. It is a "powerful tool" for creating empty files and updating timestamps. Just ensure attention to permissions and path validity when using it.

Read More
The `cp` Command: How to Copy Files in Ubuntu

In the Ubuntu system, `cp` is a basic command for copying files/directories without deleting the source files. The basic format is `cp source_file/directory target_location`. Common parameters include: `-i` (prompt for confirmation before overwriting), `-r` (recursively copy directories, **required**), and `-v` (show detailed process). **Scenario Examples**: - Copy a single file to the current directory: `cp test.txt .` - Copy to a specified directory (requires `docs` to exist): `cp test.txt docs/` - Copy multiple files: `cp file1.txt file2.txt docs/` - Copy a directory (must use `-r`; auto-creates target directory): `cp -r docs/ backup/` - Confirm overwrites with `-i`: `cp -i test.txt docs/` **Notes**: - Omitting `-r` when copying a directory will cause failure. - The target file is overwritten by default when it exists; use `-i` for safety. - Hidden files (e.g., `.bashrc`) can be copied directly. - `-r` automatically creates the target directory if it does not exist. **Key Takeaways**: Basic format, `-r` for directories, `-i` to confirm overwrites, and `-v` to view the process.

Read More